package kor.ketti.team;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class EditorActivity extends Activity implements OnClickListener {
	
	Context mContext;
	LayoutInflater inflater;
	
	AlertDialog dialog;
	
	TextView a_edit,b_edit,c_edit;
	int backgroundColor_sourceSeparator;
	
    /** Called when the activity is first created. */
    @Override
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_title);
        
        // get temp_handle
        TextView skip = (TextView)findViewById(R.id.skip);
        skip.setOnClickListener(this);
        
        // get resource color for background color
        backgroundColor_sourceSeparator = getResources().getColor(R.color.backgroundColor_sourceSeparator);
        
        /* for custom dialog, find_dialog & goto_dialog */
        {
        // step1:get context
		mContext = getApplicationContext();
		
		// step2:get inflater that return view
		inflater = (LayoutInflater)mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
        }
    }
    
    private void startEditor()
    {
    	setContentView(R.layout.view_source);
		
		// get handle of edit_view
		a_edit = (TextView)findViewById(R.id.a_source_view);
		a_edit.setOnClickListener(this);
		a_edit.setBackgroundColor(backgroundColor_sourceSeparator);
		
		b_edit = (TextView)findViewById(R.id.b_source_view);
		b_edit.setOnClickListener(this);
		
		c_edit = (TextView)findViewById(R.id.c_source_view);
		c_edit.setOnClickListener(this);
    }
    
	@Override
	public void onClick(View arg0)
	{
		// TODO Auto-generated method stub
		switch(arg0.getId())
		{
		case R.id.skip:
			startEditor();
	        break;
		case R.id.a_source_view:
			setTitle(R.string.app_name);
			setTitle(getTitle() + " - " + "a_source_filename");
			a_edit.setBackgroundColor(backgroundColor_sourceSeparator);
	        b_edit.setBackgroundColor(0);
	        c_edit.setBackgroundColor(0);
			break;
		case R.id.b_source_view:
			setTitle(R.string.app_name);
			setTitle(getTitle() + " - " + "b_source_filename");
			a_edit.setBackgroundColor(0);
			b_edit.setBackgroundColor(backgroundColor_sourceSeparator);
			c_edit.setBackgroundColor(0);
			break;
		case R.id.c_source_view:
			setTitle(R.string.app_name);
			setTitle(getTitle() + " - " + "c_source_filename");
			a_edit.setBackgroundColor(0);
			b_edit.setBackgroundColor(0);
			c_edit.setBackgroundColor(backgroundColor_sourceSeparator);
			break;
		case R.id.go_button:
			/* implement to goto line */
			
			//dialog.hide();
			break;
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// TODO Auto-generated method stub
		MenuInflater inflater = this.getMenuInflater();
		inflater.inflate(R.menu.options_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		// TODO Auto-generated method stub
		switch(item.getItemId())
		{
		case R.id.Goto:
			// step3:get root-view that inflate custom-view on dialog
			View goto_layout = inflater.inflate(R.layout.dialog_goto,
					(ViewGroup) findViewById(R.id.goto_layout));
			
			// step4:build dialog
			AlertDialog.Builder bGoto = new AlertDialog.Builder(this);
			bGoto.setTitle("Goto");
			bGoto.setView(goto_layout);
			
			// step5:create dialog & show 
			dialog = bGoto.create();
			dialog.show();
			return true;
		case R.id.undo:
			/* implement undo */
			return true;
		case R.id.annotation_1:
			/* implement to add '//' */
			return true;
		case R.id.annotation_2:
			/* implement to add '/*' */
			return true;
		}
		return false;
	}
    
}